package com.youth.koodoReaderManager.controller;

import com.youth.koodoReaderManager.entity.HtmlBook;
import com.youth.koodoReaderManager.service.HtmlBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/htmlBook")
@Api(tags = "HTML书籍管理", description = "提供HTML书籍的CRUD操作")
public class HtmlBookController {

    private final HtmlBookService htmlBookService;

    @Autowired
    public HtmlBookController(HtmlBookService htmlBookService) {
        this.htmlBookService = htmlBookService;
    }

    @GetMapping
    @ApiOperation(value = "获取所有HTML书籍", notes = "获取系统中所有的HTML书籍信息")
    public List<HtmlBook> listHtmlBooks() {
        return htmlBookService.list();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据ID获取HTML书籍", notes = "根据提供的ID获取特定HTML书籍的详细信息")
    public HtmlBook getHtmlBookById(@PathVariable String id) {
        return htmlBookService.getById(id);
    }

    @PostMapping
    @ApiOperation(value = "创建新的HTML书籍", notes = "创建一个新的HTML书籍记录")
    public boolean createHtmlBook(@RequestBody HtmlBook htmlBook) {
        return htmlBookService.save(htmlBook);
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新HTML书籍信息", notes = "根据ID更新特定HTML书籍的信息")
    public boolean updateHtmlBook(@PathVariable String id, @RequestBody HtmlBook htmlBook) {
        return htmlBookService.updateById(htmlBook);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除HTML书籍", notes = "根据ID删除特定的HTML书籍")
    public boolean deleteHtmlBook(@PathVariable String id) {
        return htmlBookService.removeById(id);
    }

    // 其他API方法，根据需要添加对应的Swagger注解...
}